import { ClientChannel } from "ssh2";
import IVsshStatus, { ClipBoardData, ClipBoardOption, FileType, IDFile } from "./IVsshStatus";

import Container from "./ui/components/main/Container";
import Connect from "./Connect";
import { Tab, TabConfig } from "./ui/core/TabBar";
import IParser from "./parser/IParser";
import box from "./view";
import Status from "./StatusManager";

export class ConnectPool{
    // private Status:IVsshStatus;
    // privateKey:Buffer
    connectPool:Map<number,Connect>=new Map<number,Connect>();
    private autoIncrement=0;

    constructor(){
        // this.Status={
        //     lineTitleVerified: false,
        //     dataLock: false,
        // }
        // this.privateKey=config.privateKey;
        // this.run();
    }

    /**
     * 测试连接
     * @returns 
     */
    async connectTest(){
        return await Connect.testConnect({
            username:Status.getUsername(),
            password:Status.getPassword(),
            host:Status.getHost(),
            port:Number(Status.getPort()),
            privateKey:Status.getPrivateKey(),
        })
    }

    async createConnect(parserCreator:(conn:Connect)=>IParser){
        let id=this.autoIncrement;
        let l= this.connectPool.set(id,await Connect.create({
            username:Status.getUsername(),
            password:Status.getPassword(),
            host:Status.getHost(),
            port:Number(Status.getPort()),
            privateKey:Status.getPrivateKey(),
            parserCreator
        }))
        this.autoIncrement++;
        console.warn("创建了连接")
        return id
    }

}

// export interface RuntimeConfig{
//     container:Container,
//     username:string,
//     password:string
//     host:string
//     port:string |number
//     privateKey:Buffer,
// }
const CONNECT_POOL= new ConnectPool();

export default CONNECT_POOL;